package fr.dauphine.td3.bdd;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import fr.dauphine.td3.emp.Poste;

@Repository
@Transactional
public class PosteDAO {
	
	private SessionFactory sessionFactory;
	
	public Session getSession() {
		return this.sessionFactory.getCurrentSession();
	}
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	@Transactional(readOnly = true)
	public List<Poste> get() {
		return (List<Poste>) getSession().createQuery("from Poste").list();
	}
	
	@Transactional(readOnly = true)
	public List<Poste> getPosteEmploye(String idEmploye) {
		
		List<Poste> lp = new ArrayList<Poste>();
		lp = (List<Poste>) getSession().load(Poste.class, idEmploye);
		
		
		return (List<Poste>) getSession().createQuery("from Poste").list();
	}

}
